package edu.hcmus.sow.dao;

import java.util.List;

import org.hibernate.criterion.Restrictions;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import edu.hcmus.sow.domain.User;

/**
 * DAO to manage User entities.
 * 
 */
@Repository
@Transactional
public class UserDAOImpl extends AbstractHibernateDAO<User, Integer> implements UserDAO {

	public List<User> findByUsername(String username, Integer clientID) throws DataAccessException {
		String queryString = "from User where clientID = ? and username like ?";
		List<User> list = executeQuery(queryString, 0, 10, clientID, username + "%");
		return list;
	}

	public List<User> getByClientID(Integer clientID) throws DataAccessException {
		String queryString = "from User where clientID = ?";
		List<User> list = executeQuery(queryString, clientID);
		return list;
	}

	public List<User> findUserByUsername(Integer clientID, String username) throws DataAccessException {
		return findByCriteria(Restrictions.eq("clientID", clientID), Restrictions.eq("username", username));
	}
}
